package com.service.Hua.Impl;

import com.mapper.Hua.MaterialWarehouseInMapper;
import com.mapper.Hua.MaterialWarehouseMapper;
import com.pojo.Hua.HuaMaterialInWarehouse;
import com.pojo.Hua.HuaMaterialWarehouse;
import com.service.Hua.IMaterialWarehouseService;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MaterialWarehouseServiceImpl implements IMaterialWarehouseService {
    @Autowired
    MaterialWarehouseMapper materialWarehouseMapper;
    @Override
    public List<HuaMaterialWarehouse> getMaterialWarehouse() {
        return materialWarehouseMapper.getMaterialWarehouse();
    }

    @Autowired
    MaterialWarehouseInMapper materialWarehouseInMapper;
    @Override
    public Res addMaterialWarehouse(HuaMaterialInWarehouse huaMaterialInWarehouse) {
        Res res = new Res();
        if (huaMaterialInWarehouse != null){
            Integer inWarehouseMaxCode = materialWarehouseInMapper.getInWarehouseMaxCode();
            if(inWarehouseMaxCode!=0 || inWarehouseMaxCode != null){
                Integer code = inWarehouseMaxCode + 1;
                huaMaterialInWarehouse.setMaterialInWarehouseCode(code.toString());
                int i = materialWarehouseMapper.addMaterialWarehouse(huaMaterialInWarehouse);
                if(i>0){
                    res.setCode(200);
                }
            }
        }else{
            res.setCode(404);
        }
        return res;
    }

    @Override
    public Res upDateWarehouseTime(String code) {
        Res res = new Res();
        int i = materialWarehouseMapper.upDateWarehouseTime(code);
        if (i>0){
            res.setCode(200);
        }else {
            res.setCode(402);
        }
        return res;
    }
}
